Paste number 27891: basically like this

Paste number 27891: basically like this
Pasted by: jsnell
When:8 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+LIR
Channel:#lisp
Paste contents:
Raw Source | XML | Display As
(defun create-lisp-mem ()
  (declare (optimize (speed 1)))
  (let ((files (directory (merge-pathnames #p"download/training_set/*.*"
                                           *root*)))
        (count 0))
    (with-open-file (map-file *map-file*
                              :direction :output
                              :if-exists :supersede
                              :element-type '(unsigned-byte 64))
      ;; Header
      (write-byte sb-vm::simple-array-unsigned-byte-60-widetag map-file)
      ;; Array size placeholder
      (write-byte 8 map-file)
      (dolist (file files)
        (print file)
        (with-open-file (stream file)
          (let ((index (parse-integer (read-line stream) :junk-allowed t)))
            (let ((lines (loop for line = (read-line stream nil nil)
                               while line
                               collect line)))
              (loop for line in lines
                    for i from 0
                    do (multiple-value-bind (uid end)
                           (parse-integer line :junk-allowed t)
                         (let* ((stars (parse-integer line
                                                      :start (1+ end)
                                                      :junk-allowed t))
                                (data
                                 (ash (logior uid
                                              (ash index 32)
                                              (ash stars (+ 32 16)))
                                      sb-vm::n-fixnum-tag-bits)))
                           (incf count)
                           (write-byte data map-file))))))))
      (file-position map-file 1)
      (write-byte (ash count sb-vm:n-fixnum-tag-bits)
                  map-file))
    (load-lisp-mem *map-file* '*ratings*)))

(defun load-lisp-mem (map-file variable)
  (with-open-file (file map-file)
    (let* ((sap (sb-posix:mmap nil
                               (file-length file)
                               sb-posix:prot-read
                               sb-posix:map-private
                               (sb-impl::fd-stream-fd file)
                               0))
           (addr (logior (sb-sys:sap-int sap)
                         sb-vm:other-pointer-lowtag)))
      (setf (symbol-value variable) (sb-kernel:make-lisp-obj addr))
      (values))))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.